package actions;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.sql.RowSet;

import model.Applicant;
import model.Database;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.ResidencySubmitForm;

public class ReviewersHomeAction extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws DbException, ClassNotFoundException, SQLException {
		
		HttpSession session = request.getSession();
		String username = request.getUserPrincipal().getName();
		int id = 0;
		try {
			id = Database.getIdByUsername(username);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (ClassNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		RowSet applicationsByReviewer = null;
		try {
			applicationsByReviewer = Database.getApplicationsByReviewer(id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// Return the rowset
		session.setAttribute("applicationsByReviewer", applicationsByReviewer);
		
		return mapping.findForward("success");
	}
}
